# -*- coding:utf-8 -*-
import sys, shutil
import os, pdb
import django

sys.path.append(".")
os.environ.update({"DJANGO_SETTINGS_MODULE": "server.settings"})
try:
    django.setup()
except:
    print("ERROR: django init Error")

from django.conf import settings

sysConfig = settings.CONFIG
from announcement.models import Announcement
from log.models import UserLog, SoftwareLog, StoreHouseLog
from need.models import SoftwareNeed, NeedHandle
from notice.models import NoticeInfo
from question.models import SoftwareQuestion, QuestionHandle
from software.models import SoftwareType, Software, SoftwareVersion, \
    SoftwareData, SoftwareCollection, SoftwareGroup, DuanInfo
from store.models import Store
from storehouse.models import Storehouse, StorehouseConnect
from system.models import System
from user.models import WarZone, Company, User, VSession, FileStore, IPSystem


def copy(oldPath, newPathDir):
    shutil.copy(oldPath, newPathDir)


if __name__ == '__main__':
    try:
        pdb.set_trace()
        Announcement.objects.all().delete()
        UserLog.objects.all().delete()
        SoftwareLog.objects.all().delete()
        StoreHouseLog.objects.all().delete()
        NoticeInfo.objects.all().delete()
        IPSystem.objects.all().delete()
        SoftwareNeed.objects.all().delete()
        NeedHandle.objects.all().delete()
        SoftwareQuestion.objects.all().delete()
        QuestionHandle.objects.all().delete()
        SoftwareCollection.objects.all().delete()
        System.objects.all().delete()
        StorehouseConnect.objects.all().delete()
        SoftwareData.objects.all().delete()
        SoftwareGroup.objects.all().delete()
        DuanInfo.objects.all().delete()
        FileStore.objects.all().delete()
        SoftwareVersion.objects.all().delete()
        Store.objects.all().delete()
        Software.objects.all().delete()
        SoftwareType.objects.all().delete()
        Storehouse.objects.all().delete()
        VSession.objects.all().delete()
        User.objects.all().delete()
        Company.objects.all().delete()
        WarZone.objects.all().delete()
        print("Tables init finish !!!!!!")
    except Exception as e:
        print("EORROR: Tables init error")
    try:
        copy(sysConfig["dataBack"], sysConfig["dataDir"])
    except Exception as e:
        print("ERROR: data dir can not be created")
